#include"processbar.h"
#include<string.h>
#include<unistd.h>

const char* lable="|/-\\";

char bar[NUM]={0};
void processbarCore(int rate)
{
  if(rate<0||rate>100) return;

  int len=strlen(lable);
  printf(BLUE"[%-100s]"NONE"[%d%%][%c]\r",bar,rate,lable[rate%len]);
  fflush(stdout);
  bar[rate++]=BODY;
  if(rate<TOP)bar[rate]=RIGHT;
}

void processbar()
{
  char bar[NUM];
  memset(bar,'\0',sizeof(bar));

  int len=strlen(lable);
  int cnt=0;
  while(cnt<=TOP)
  {
      printf("[%-100s][%d%%][%c]\r",bar,cnt,lable[cnt%len]);
      fflush(stdout);
      bar[cnt++]=RIGHT;
      if(cnt>0){
          bar[cnt-1]=BODY;
          if(cnt<TOP)bar[cnt]=RIGHT;
      }
      usleep(100000);
  }
  printf("\n");
}

